<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('任务转移审核')" />
    <th:block th:include="include :: bootstrap-select-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-task-replace-edit">
        <div class="col-md-12">
            <div class="form-group">
                <label class="col-sm-2 control-label">任务标题：</label>
                <div class="col-sm-9">
                    <input type="text" th:field="*{replace.taskTitle}"  class="form-control" readonly>
                    <input id="transferId" name="transferId" th:value="${replace.transferId}" type="hidden"/>
                    <input id="taskId" name="taskId" th:value="${replace.taskId}" type="hidden"/>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">任务内容：</label>
                <div class="col-sm-9">
                    <textarea type="text"  multiple th:field="*{replace.content}" class="form-control"  readonly ></textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">申请人员：</label>
                <div class="col-sm-9">
                    <input type="text" class="form-control" th:value="${replace.userName}" th:field="*{replace.userName}" readonly>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">任务时间：</label>
                <div class="col-sm-9">
                    <div class="input-daterange input-group">
                        <input type="text" class="input-sm form-control" id="datetimepicker-startTime" th:field="*{replace.startTime}" placeholder="开始时间" readonly>
                        <span class="input-group-addon">-</span>
                        <input type="text" class="input-sm form-control" id="datetimepicker-endTime" placeholder="结束时间" th:field="*{replace.endTime}" readonly>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">申请时间：</label>
                <div class="col-sm-9">
                    <input type="text" class="input-sm form-control" id="datetimepicker-delayTime" th:field="*{replace.applicantionTime}" placeholder="延期时间" readonly>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">转移原因：</label>
                <div class="col-sm-9">
                    <textarea type="text" multiple th:field="*{replace.transferReason}" class="form-control" placeholder="请输入申请原因" readonly ></textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">是否批准：</label>
                <div class="col-sm-9">
                    <select class="form-control select2-multiple" name="pass" id="pass" th:field="*{replace.pass}" required>
                        <option value="">请选择</option>
                        <option value="1">通过</option>
                        <option value="0">未通过</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">接替人：</label>
                <div class="col-sm-3">
                    <select class="form-control" name="comp" id="comp">
                        <option value="">请选择公司</option>
                    </select>
                </div>
                <div class="col-sm-3">
                    <select class="form-control" name="dept" id="dept">
                        <option value="">请选择部门</option>
                    </select>
                </div>
                <div class="col-sm-3">
                    <select class="form-control" name="successor" id="successor" required>
                        <option value="">请选择转交人</option>
                        <th:block th:if="${replace.successor}!=null">
                            <option th:text="${replace.succeName}" th:value="${replace.successor}" th:field="*{replace.successor}"></option>
                        </th:block>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">详细意见：</label>
                <div class="col-sm-9">
                    <textarea type="text" id="opinion" name="opinion" multiple th:field="*{replace.opinion}" class="form-control" placeholder="请输入意见" maxlength="255" ></textarea>
                </div>
            </div>
        </div>
    </form>
</div>

<th:block th:include="include :: footer" />
<th:block th:include="include :: bootstrap-select-js" />
<script type="text/javascript">
    var prefix = ctx + "system/task/replace";

    function getApplicant() {
        $.ajax({
            url: "/system/dept/selectCompAll",
            success: function (result) {
                $.each(result, function (index, value) {
                    var name = value.deptName;
                    var id = value.deptId;
                    $('#comp').append("<option value='" + id + "'>" + name + "</option>");
                });
                $("#comp").selectpicker('refresh');
            }
        });
        $("#comp").bind("change", function() {
            //刷新选中第一条空数据
            document.getElementById("dept").options.selectedIndex = 0;
            document.getElementById("successor").options.selectedIndex = 0;
            //只保留下拉框中第一条空数据
            document.getElementById("dept").options.length = 1;
            document.getElementById("successor").options.length = 1;
            $("#successor").selectpicker('refresh');
            var deptId = $(this).val(); //获取当前下拉框name属性的值
            console.log(deptId);
            $.ajax({
                type : "POST",
                url : "/system/dept/selectDeptAll",
                data : {
                    "deptId" : deptId
                },
                success : function(result) {
                    $.each(result, function (index, value) {
                        var name = value.deptName;
                        var id = value.deptId;
                        $('#dept').append("<option value='" + id + "'>" + name + "</option>");
                    });
                    $("#dept").selectpicker('refresh');
                },
            });
        });
        $("#dept").bind("change", function() {
            //刷新选中第一条空数据
            document.getElementById("successor").options.selectedIndex = 0;
            //只保留下拉框中第一条空数据
            document.getElementById("successor").options.length = 1;
            var deptId = $(this).val(); //获取当前下拉框name属性的值
            console.log(deptId);
            $.ajax({
                type : "POST",
                url : "/system/user/selectUsersBydeptId",
                data : {
                    "deptId" : deptId
                },
                success : function(result) {
                    $.each(result, function (index, value) {
                        var name = value.userName;
                        var id = value.userId;
                        $('#successor').append("<option value='" + id + "'>" + name + "</option>");
                    });
                    $("#successor").selectpicker('refresh');
                },
            });
        });
    }
    getApplicant();


    $("#form-task-replace-edit").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/edit", $('#form-task-replace-edit').serialize());
        }
    }

</script>
</body>
</html>
